import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/preview',
    component: Layout,
    // redirect: '/networkParameters',
    children: [{
      path: '/preview',
      name: 'Preview',
      component: () => import('@/views/preview/videoPreview'),
      meta: { title: '视频预览', icon: 'el-icon-video-camera-solid' }
    }]
  },
  {
    path: '/networkParameters',
    component: Layout,
    // redirect: '/networkParameters',
    children: [{
      path: '/networkParameters',
      name: 'NetworkParameters',
      component: () => import('@/views/networkParameters/index'),
      meta: { title: '网络参数', icon: 'el-icon-s-promotion' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: { title: 'Dashboard', icon: 'dashboard' }
  //   }]
  // },
  {
    path: '/sdCard',
    component: Layout,
    children: [{
      path: '/sdCard',
      name: 'sdCard',
      component: () => import('@/views/sdCard/sdCard'),
      meta: { title: 'SD卡信息', icon: 'dashboard' }
    }]
  },
  {
    path: '/form',
    hidden:true,
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },
  {
    path: '/businessConfiguration',
    component: Layout,
    // redirect: '/example/table',
    name: 'BusinessConfiguration',
    meta: { title: '业务配置', icon: 'tree' },
    children: [
      {
        path: 'algorithm',
        name: 'Algorithm',
        component: () => import('@/views/businessConfiguration/algorithm'),
        meta: { title: '算法检测参数'}
      },
      {
        path: 'videoConfig',
        name: 'VideoConfig',
        component: () => import('@/views/businessConfiguration/videoConfig'),
        meta: { title: '录像参数'}
      },
      {
        path: 'devlocation',
        name: 'Devlocation',
        component: () => import('@/views/businessConfiguration/devlocation'),
        meta: { title: '设备位置'}
      },
      {
        path: 'boardingDirection',
        name: 'BoardingDirection',
        component: () => import('@/views/businessConfiguration/boardingDirection'),
        meta: { title: '模式选择'}
      },
      {
        path: 'deviceID',
        name: 'DeviceID',
        component: () => import('@/views/businessConfiguration/deviceID'),
        meta: { title: '设备ID'}
      },
      {
        path: 'importAuthorizationCode',
        name: 'ImportAuthorizationCode',
        component: () => import('@/views/businessConfiguration/importAuthorizationCode'),
        meta: { title: '导入授权码'}
      }
      ,
      {
        path: 'platformServer',
        name: 'PlatformServer',
        component: () => import('@/views/businessConfiguration/platformServer'),
        meta: { title: '平台服务器参数'}
      }
      ,
      {
        path: 'ntpServer',
        name: 'NtpServer',
        component: () => import('@/views/businessConfiguration/ntpServer'),
        meta: { title: 'NTP服务器参数'}
      },
      {
        path: 'osdParameters',
        name: 'OSDParameters',
        component: () => import('@/views/businessConfiguration/osdParameters'),
        meta: { title: 'OSD参数'}
      },
      {
        path: 'lightingControl',
        name: 'LightingControl',
        component: () => import('@/views/businessConfiguration/lightingControl'),
        meta: { title: '灯光控制参数'}
      },
      {
        path: 'sipParameters',
        name: 'SipParameters',
        component: () => import('@/views/businessConfiguration/sipParameters'),
        meta: { title: 'SIP对讲参数'}
      }
    ]
  },

  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: 'Example', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: 'Table', icon: 'table' }
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/tree/index'),
  //       meta: { title: 'Tree', icon: 'tree' }
  //     }
  //   ]
  // },
  {
    path: '/systemFunction',
    component: Layout,
    // redirect: '/example/table',
    name: 'systemFunction',
    meta: { title: '辅助功能', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'clearDatabase',
        name: 'ClearDatabase',
        component: () => import('@/views/systemFunction/clearDatabase'),
        meta: { title: '删除数据库'}
      },
      {
        path: 'level',
        name: 'Level',
        component: () => import('@/views/systemFunction/level'),
        meta: { title: '日志'}
      },
      {
        path: 'restart',
        name: 'Restart',
        component: () => import('@/views/systemFunction/restart'),
        meta: { title: '重启'}
      },
      {
        path: 'timings',
        name: 'Timings',
        component: () => import('@/views/systemFunction/timings'),
        meta: { title: '校时'}
      },
      {
        path: 'upgrade',
        name: 'Upgrade',
        component: () => import('@/views/systemFunction/upgrade'),
        meta: { title: '升级'}
      }
      ,

      {
        path: 'version',
        name: 'Version',
        component: () => import('@/views/systemFunction/version'),
        meta: { title: '版本'}
      },
    ]
  },



  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },
  //
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
